import ecenter from '../lib/node_modules/ecenter-core/dist/ecenter-core.es';

let router = null;//ecenter.router.create(config, import.meta.glob('./views/**/*.vue'));
const install = (app) => {
    if (install.installed) return;
    install.installed = true;
    const ecenterMUI = app.config.globalProperties.$ecenterMUI;
    /**
     * 若views 根目录下没有直接设置index.vue和login.vue则必须在路由表里配置首页和登录页，其他路由无需写
     * auth:是否需要权限控制
     * title:页面标题
     * */
    let _routers = ecenterMUI['ecm-routers'];
    const config = [
        {
            path: '/login',
            name: 'login',
            component: ecenterMUI.EcmLogin,
            meta: {
                title: '登录'
            }
        },
        {
            path: '/',
            name: 'index',
            component: () => import("./views/index.vue"),
            meta: {
                auth:true,
                title: '首页'
            },
        },
        ..._routers
    ];
    let base_url = location.pathname + location.search;
    router = ecenter.router.create(config, import.meta.globEager('./views/**/*.vue'), base_url);
    app.use(router);
    app.config.globalProperties.$router = router;
}

export default {install, router}
